import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:myapp/app/theme/app_color.dart';

const String _AVATAR =
    "https://gimg2.baidu.com/image_search/src=http%3A%2F%2Finews.gtimg.com%2Fnewsapp_bt%2F0%2F13926895099%2F641&refer=http%3A%2F%2Finews.gtimg.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1632797230&t=b5cfeaf64f4237bebd957a536dfc3846";

Widget _buildClose() {
  return IconButton(
      onPressed: () {Get.back();},
      icon: Icon(
        Icons.close,
        color: AppColor.hex_666,
      ));
}

Widget _buildHeader() {
  return Container(
    margin: EdgeInsets.only(top: 20, left: 20, right: 20),
    child: Row(
      mainAxisAlignment: MainAxisAlignment.spaceBetween,
      children: [
        Row(
          children: [
            ClipRRect(
              child: Image.network(
                _AVATAR,
                height: 40,
                width: 40,
                fit: BoxFit.cover,
              ),
              borderRadius: BorderRadius.all(Radius.circular(20)),
            ),
            Padding(
              padding: EdgeInsets.only(left: 10),
              child: Text(
                "Violet",
                style: TextStyle(color: AppColor.hex_333, fontSize: 14),
              ),
            ),
          ],
        ),
        TextButton(
          onPressed: () {},
          child: Text("草稿箱(7)",
              style: TextStyle(color: AppColor.hex_333, fontSize: 14)),
          style: ButtonStyle(enableFeedback: false),
        ),
      ],
    ),
  );
}

Widget _buildOperationItem(String name, IconData icon) {
  return Column(
    children: [
      Icon(
        icon,
        color: AppColor.red80,
      ),
      Padding(
        padding: EdgeInsets.only(top: 5),
        child: Text(
          name,
          style: TextStyle(fontSize: 14, color: AppColor.hex_333),
        ),
      ),
    ],
  );
}

Widget _buildOperation() {
  return Container(
    margin: EdgeInsets.only(top: 35),
    child: Row(
      children: [
        Expanded(child: _buildOperationItem("微头条", Icons.print)),
        Expanded(child: _buildOperationItem("文章", Icons.style)),
        Expanded(child: _buildOperationItem("问答", Icons.insert_drive_file)),
        Expanded(
            child:
                _buildOperationItem("视频", Icons.account_balance_wallet_sharp)),
        Expanded(child: _buildOperationItem("直播", Icons.video_collection)),
      ],
    ),
  );
}

Widget _buildListTitle(String leadingText, String trailingText) {
  return Container(
    child: Row(
      children: [
        Text(
          leadingText,
          style: TextStyle(fontSize: 16, color: AppColor.hex_333),
        ),
        Text(
          "$trailingText >",
          style: TextStyle(fontSize: 14, color: AppColor.hex_ddd),
        ),
      ],
      mainAxisAlignment: MainAxisAlignment.spaceBetween,
    ),
    margin: EdgeInsets.only(left: 20, right: 20),
    padding: EdgeInsets.only(top: 20, bottom: 20),
    decoration: BoxDecoration(
      border: Border(
        bottom: BorderSide(
          color: AppColor.hex_ddd20,
        ),
      ),
    ),
  );
}

class HomeBottomSheet extends BottomSheet {
  HomeBottomSheet()
      : super(
            enableDrag: false,
            backgroundColor: AppColor.white,
            shape: RoundedRectangleBorder(borderRadius: BorderRadius.only(topLeft: Radius.circular(10), topRight: Radius.circular(10))),
            onClosing: () {},
            builder: (context) {
              return IntrinsicHeight(
                child: Container(
                  child: Column(
                    children: [
                      _buildHeader(),
                      _buildOperation(),
                      _buildListTitle("创作灵感", "为你推荐热门话题"),
                      _buildListTitle("创作活动", "参与生活，赢取奖励"),
                      _buildClose(),
                    ],
                  ),
                ),
              );
            });
}
